package cn.tedu.management.portal.controller;


import cn.tedu.management.portal.ex.ServiceException;
import cn.tedu.management.portal.mapper.PerformanceMapper;
import cn.tedu.management.portal.model.Performance;
import cn.tedu.management.portal.service.impl.PerformanceServiceImpl;
import cn.tedu.management.portal.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author tedu.cn
 * @since 2020-12-08
 */
@RestController
@RequestMapping("/portal/performance")
public class PerformanceController {

    @Autowired
    PerformanceMapper performanceMapper;

    // http://localhost:8080/portal/performance/delete?id=1
    @GetMapping("/delete")
    public R<Void> delete(int id){

        performanceMapper.deleteById(id);
        return R.ok();

    }

    @Autowired
    PerformanceServiceImpl performanceService;

    // http://localhost:8080/portal/performance/update?staffId=9&allPerformance=45
    @GetMapping("/update")
    public R<Void> update(int staffId,double allPerformance){

        try {
            performanceService.updateByStaffId(staffId,allPerformance);
            return R.ok();
        }catch (ServiceException e){
            return R.failure(R.State.ERR_INSERT,e);

        }


    }



    // http://localhost:8080/portal/performance/find?id=1
    @GetMapping("/find")
    public R<Performance> update(int id){
        Performance performance = performanceMapper.selectById(id);
        return R.ok(performance);
    }


}
